package activiti;

import org.activiti.engine.*;
import org.activiti.engine.identity.User;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.ProcessDefinition;

import java.io.InputStream;

public class Sixth {

    public static void main(String[] args) {
        // 创建流程引擎
        ProcessEngine pe=ProcessEngines.getDefaultProcessEngine();
        //
        RepositoryService res=pe.getRepositoryService();
        RuntimeService rus=pe.getRuntimeService();
        TaskService ts=pe.getTaskService();
        IdentityService ids=pe.getIdentityService();

        InputStream is = Sixth.class.getClassLoader().getResourceAsStream("diagramdemo.png");

        Deployment dep=res.createDeployment().addClasspathResource("diagramdemo.bpmn").addInputStream("PNG",is).addString("Text", "This is diagramdemo  string resource").name("diagramdemo").category("resource").addClasspathResource("d4.bpmn").addClasspathResource("d4.png").category("resource").name("d4").category("resource").enableDuplicateFiltering().deploy();

        // Deployment dep=res.createDeployment().addClasspathResource("diagramdemo.bpmn").addInputStream("PNG",is).addString("Text", "This is diagramdemo  string resource").name("diagramdemo").category("resource").addClasspathResource("d4.bpmn").addClasspathResource("d4.png").category("resource").name("d4").category("resource").enableDuplicateFiltering().deploy();


		/*
		DeploymentBuilder db1=res.createDeployment();
		DeploymentBuilder db2=res.createDeployment();
		db1=db1.addClasspathResource("diagramdemo.bpmn").name("Diagram").category("DIAGRAM");
		System.out.println("请选择表act_re_deployment中所有的记录");

		Deployment dm1=db1.deploy();
		System.out.println("Please select the all records of the table act_re_deployment again to see the diffrent.");
		*/
	   /*
		db2=db2.addInputStream("DiagramPng",is).name("Png").category("PNG");
		System.out.println("请选择表act_re_deployment中所有的记录");
		Deployment dm2=db2.deploy();
		System.out.println("请再次选择表act_re_deployment中所有的记录并观察不同");
		*/

		/*
		List<Deployment> queryDeps=res.createDeploymentQuery().deploymentCategory("resource").list();
		for(Deployment queryDep:queryDeps) {
		System.out.println("ID:"+queryDep.getId()+" Category:"+queryDep.getCategory()+" Deployment Time:"+queryDep.getDeploymentTime());
		}
		*/

        Deployment queryDep=res.createDeploymentQuery().deploymentName("diagramdemo").singleResult();

        ProcessDefinition queryPD=res.createProcessDefinitionQuery().deploymentId(queryDep.getId()).singleResult();

        User newUser=ids.newUser("001");
        newUser.setEmail("OneUser@163.com");
        newUser.setFirstName("奥特曼");
        newUser.setLastName("迪迦");
        newUser.setPassword("123456");
        ids.saveUser(newUser);

        res.addCandidateStarterUser(queryPD.getId(), newUser.getId());

        System.out.println("流程定义的 ID:"+queryPD.getId());
        System.out.println("流程定义的 Key:"+queryPD.getKey());
        System.out.println("流程定义的 Name:"+queryPD.getName());
		/*
	   ProcessInstance pi1=rus.startProcessInstanceByKey("vacationRequest");
	   ProcessInstance pi2=rus.startProcessInstanceByKey("vacationRequest");
	   */

        ids.deleteUser(newUser.getId());
    }
}
